<?php


namespace apps\marriage\core\service;

use apps\marriage\core\model\MemberRechargeRecord;
use vm\com\BaseService;

class MemberRechargeRecordService extends BaseService
{

    /**
     * @return MemberRechargeRecord
     */
    protected function getModel()
    {
        return new MemberRechargeRecord();
    }

    public function create(array $data)
    {
        $data['dateline'] = time();
        return parent::create($data);
    }

    public function count(array $params = [])
    {
        $model = $this->getModel();
        foreach ($params as $key => $val) {
            if(is_array($val)) {
                $model = $model->where($key, $val[0], $val[1]);
            } else if($key == 'min_dateline') {
                $model = $model->where('dateline', '>=', $val);
            } else if($key == 'max_dateline') {
                $model = $model->where('dateline', '<=', $val);
            } else {
                $model = $model->where($key, $val);
            }
        }
        return $model->count();
    }
}